﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using System.Data.SqlClient;

namespace Takenlijst
{
    public partial class Form2 : Form
    {
        string naam = "";
        string status = "";

        public Form2()
        {
            InitializeComponent();
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
           naam = textBox1.Text;
           status = comboBox1.SelectedItem.ToString(); //< - - peters plekje

             if (naam != "" && status != "")
             { 
                saveTask();
             }
            else
            {
                MessageBox.Show("Niet alle velden zijn ingevuld!");
            }
        }

        //ProjectID is nog een placeholder omdat de takenlijst nog bij de rest moet worden samengevoegd

        public void saveTask()
        {
            MySqlConnection grabConnection = new MySqlConnection("Server=instance8003.db.xeround.com;Port=6006;Database=GrabCollab;Uid=cookicom0;Pwd=pizzahut91;");
            MySqlCommand taken = new MySqlCommand("INSERT INTO taken (TaakID, Taak, ProjectID, Status )" + "VALUES ('','"+naam+"', 1,'"+status+"')", grabConnection);
         //  taken.Parameters.Add(new MySqlParameter("naam", naam));
         //  taken.Parameters.Add(new MySqlParameter("status", status));



            try
            {
                grabConnection.Open();
                taken.ExecuteNonQuery();
            }
            catch (Exception)
            {
                MessageBox.Show("Sql error detected!");
            }
            finally
            {
                grabConnection.Close();
               MessageBox.Show("Taak succesvol opgeslagen!");
               this.Close();
            }
        }



    }
}
